(function(a) {
	a.fed = a.fed || {};
	a.extend(a.fed, {
		page: function(obj,options) {
			var o=$.extend({
				currentPage:1,
				totalAmount:"",
				totalAmountShow:false,
				onePagehide:true, //只有1页时是否影藏翻页
				url:"",
				showpage:5,
				callback:function(current_Page){

				}
			},options);
			var no_length=o.totalAmount;

			if((o.totalAmount==1&&o.onePagehide)||o.totalAmount==0){
				$(obj).hide();
			}else{
				$(obj).show();
			}
			if(!o.currentPage){
				o.currentPage=1;
			}
			var currentPage=null;
			function pageHtmlList(index){
				var index=parseInt(index);
				var page_front='<div class="page-list">';

				var frist_page=	'<a class="page_no" rel="'+parseInt(1)+'" href="#"><span>1</span></a>';
				var	pre_page ='<a class="page_no f-prev" rel="'+parseInt(index-1)+'" href="#"><i>&lt; 上一页</i></a>';
				var	next_page ='<a class="page_no f-next" rel="'+parseInt(index+1)+'" href="#">下一页<i>&gt;</i></a>';
				var	last_page='<a class="page_no" rel="'+parseInt(no_length)+'" href="#"><span>'+no_length+'</span></a>';
				var total_amount='';
				if(o.totalAmountShow){
					total_amount='<span class="page_total">共'+o.totalAmount+'页</span>';
				}
				var	page_end='  </div>';
				var	page_end='	<span class="page-skip">到第';
				page_end+='  <input type="text" class="input">';
				page_end+='  页';
				page_end+='  <a class="sub-btn" href="javascript:;">确定</a>';
				page_end+='</span>';

				var page_content=" ";
				var page_break_front="<span class='ellipsis'>...</span>";
				var page_break_end="<span class='ellipsis'>...</span>";


				if(index==0){index=1}
				if(index==1){frist_page='';pre_page='';}
				if(index>=2&&index<=3){frist_page='';}

				if(index>no_length){index=no_length;}
				if(index>no_length-3&&index<=no_length-1){last_page='';}

				if(index==no_length){next_page='';last_page='';}

				if(no_length<=5){pre_page='';next_page='';}

				for(var i=index-2;i<parseInt(parseInt(index)+parseInt(3));i++){
					if(i<1){i=1;}
					if(i<3){page_break_front='';}
					//alert(i+" "+parseInt(parseInt(index)+parseInt(3)))
					if(i>no_length){break;}
					if(i>no_length-2){page_break_end='';}
					if(i==index){
						page_content+='<span class="current pspan current" rel="'+i+'">'+i+'</span>';
					}else{
						page_content+='<a rel="'+i+'" class="page_no"  href="#">'+i+'</a>';
					}
				}

				var page=page_front + pre_page + frist_page + page_break_front + page_content + page_break_end  + last_page + next_page + total_amount + page_end;
				$(obj).html(page);
				$(obj).find(".page_no").unbind("click");
				$(obj).find(".page_no").bind("click",function(){
					var currentPage=$(this).attr("rel");
					o.callback(currentPage);
					//alert(o.url+"?page="+currentPage);
					pageHtmlList(currentPage);
					return false;
				});
				//去除整数外的字符
				$(obj).find(".input").unbind("keyup");
				$(obj).find(".input").bind("keyup",function(){
					var _thisval=this.value,
							space=/[^\d]/;
					if( space.test(_thisval) ){
						this.value = _thisval.replace( space, '' );
					}
				});
				$(obj).find(".sub-btn").unbind("click");
				$(obj).find(".sub-btn").bind("click",function(){
					var gopage=parseInt($.trim($(obj).find(".input").val()));
					//console.log(isNaN(gopage));
					if(!isNaN(gopage)){
						if((gopage<=no_length) && no_length>0 && gopage>0){
							o.callback(gopage);
							pageHtmlList(gopage);
						}else{
							alert("您所输入的页数不存在");
							$(obj).find(".input").val("");
						}
					}else{
						alert("请输入页数");
					}
					return false;
					//return o.url+"?page="+gopage;
				});
			}

			pageHtmlList(o.currentPage);

		}
	})
})(jQuery);